using System;
using System.Runtime.InteropServices;
using System.Windows.Forms;

namespace RegexEditor
{
	public class PaintLock : IDisposable
	{
		#region Private Fields

		private Control _control;

		#endregion

		#region Constructors

		public PaintLock(Control control)
		{
			_control = control;
			LockWindowUpdate(control.Handle.ToInt32());
			control.SuspendLayout();
		}

		#endregion

		#region Public Members

		public void Dispose()
		{
			LockWindowUpdate(0);
			_control.ResumeLayout();
		}

		#endregion

		#region Private Members

		[DllImport("user32", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
		private static extern int LockWindowUpdate(int hWnd);

		#endregion
	}
}
